package com.bzkj.web.controller.docmentprocess;

import com.bzkj.common.annotation.Log;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.msfx.service.RelationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @projectName: btyy
 * @package: com.ruoyi.web.controller.docmentprocess
 * @className: RelationContorller
 * @description: 关联关系文件控制层
 * @author: C1309
 * @createDate: 2024年03月21日
 * @version: v1.0
 */
@RestController
@RequestMapping("/btrh/relation")
public class RelationController extends BaseController {

    @Resource
    private RelationService relationService;


    /**
     * 查询关联关系单据列表
     *
     * @param beginTime  查询开始时间
     * @param endTime    查询结束时间

     * @return 查询结果
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('document:relation:list')")
    public TableDataInfo queryRelationList(@RequestParam(value = "beginDate", defaultValue = "") String beginTime,
                                           @RequestParam(value = "endDate", defaultValue = "") String endTime,
                                           @RequestParam(value = "flag", defaultValue = "0") String orderState,
                                           @RequestParam(value = "orderId", required = false) String orderId) {
        return  relationService.queryRelationList(beginTime, endTime, orderState, orderId);
    }

    /**
     * 查询指定关联关系文件的追溯码详情
     *
     * @param id     任务编号
     * @param typeNo 子类编码
     * @param entId  工厂ID
     * @return 查询结果
     */
    @GetMapping("/code")
    @PreAuthorize("@ss.hasPermi('document:relation:list')")
    public AjaxResult queryCode(@RequestParam("relationId") String id, @RequestParam("typeNo") String typeNo, @RequestParam("entId") String entId) {
        return relationService.queryRelationCode(id, typeNo, entId);
    }

    /**
     * 导出关联关系文件
     *
     * @param ids 单据id
     * @return 查询结果
     */
    @GetMapping("/export/{ids}")
    @PreAuthorize("@ss.hasPermi('document:relation:export')")
    @Log(title = "关联关系文件", businessType = BusinessType.EXPORT)
    public AjaxResult exportXml(@PathVariable("ids") ArrayList<String> ids) {
        return relationService.exportXml(ids);
    }

    /**
     * 删除（重做）关联关系单据
     *
     * @param relationId 单据ID
     * @return 删除结果
     */
    @DeleteMapping("/{relationId}")
    @PreAuthorize("@ss.hasPermi('document:relation:remove')")
    @Log(title = "关联关系文件", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable("relationId") String relationId) {

        return relationService.removeByIds(relationId);
    }
}
